<ui:composition template="/pages/popup_page.xhtml"
  xmlns="http://www.w3.org/1999/xhtml"
  xmlns:ui="http://java.sun.com/jsf/facelets"
  xmlns:f="http://java.sun.com/jsf/core"
  xmlns:h="http://java.sun.com/jsf/html"
  xmlns:c="http://java.sun.com/jstl/core"
  xmlns:a4j="http://richfaces.org/a4j"
  xmlns:nxd="http://nuxeo.org/nxweb/document"
  xmlns:nxl="http://nuxeo.org/nxforms/layout"
  xmlns:nxu="http://nuxeo.org/nxweb/util">

  <ui:define name="body">

    <ui:include src="/incl/message_banner.xhtml"/>

    <div class="infoView nxPrevious">
      <a class="" href="#" onclick="previousInfoView(); return false;"></a>
    </div>
    <div class="infoView nxNext">
      <a class="next" href="#" onclick="nextInfoView(); return false;"></a>
    </div>

    <nxl:layout value="#{currentDocument}" name="gridInfoViewLayout" mode="view" />

    <h:outputScript target="#{pageJsTarget}">
      jQuery(document).ready(function() {
        // focus inside the iframe
        jQuery(".infoView.nxNext a").focus();

        // allow fullscreen, mainly useful for the video player
        jQuery("#fancybox-frame", parent.document).attr("allowFullscreen", true);

        jQuery(document).keydown(function(e) {
          switch(e.which) {
            case jQuery.ui.keyCode.LEFT:
              previousInfoView();
              break;
            case jQuery.ui.keyCode.RIGHT:
              nextInfoView();
              break;
            case jQuery.ui.keyCode.ESCAPE:
              parent.jQuery.fancybox.close();
              break;
            default:
              return;
          }
          e.preventDefault();
        });
      });

      function previousInfoView() {
        var urls = parent.nuxeo.infoView.infoViewUrls;
        var currentUrl = [location.protocol, '//', location.host, location.pathname].join('');
        var index = urls.indexOf(currentUrl);
        if (index === 0) {
          // previous page
          parent.nuxeo.infoView.previousPageAndOpenInfoView();
        } else {
          window.location.href = urls[index - 1] + "?conversationId=" + currentConversationId;
        }
      }

      function nextInfoView() {
        var urls = parent.nuxeo.infoView.infoViewUrls;
        var currentUrl = [location.protocol, '//', location.host, location.pathname].join('');
        var index = urls.indexOf(currentUrl);
        if (index === urls.length - 1) {
          // next page
          parent.nuxeo.infoView.nextPageAndOpenInfoView();
        } else {
          window.location.href = urls[index + 1] + "?conversationId=" + currentConversationId;
        }
      }
    </h:outputScript>
  </ui:define>

</ui:composition>